
import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author leehoa
 */
public class JavaMail {
    public static void main(String[] args) throws Exception {
        
        System.out.println("main");
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);
        String receive = "thienhaxaxoi_1804@yahoo.com";
        String receive1 = "hai.lt@nttnetworks.com";
        String receive2 = "hailt88@zing.vn";
        

        String msgBody = "hello\r\n...How are you?";

        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("haithanh.uit@gmail.com", "Example.com Admin"));
            msg.addRecipient(Message.RecipientType.TO,
                             new InternetAddress(receive2, "Mr. LeeThanh"));
            msg.setSubject("Your Example.com account has been activated");
            msg.setText(msgBody);
            Transport.send(msg);
            System.out.println("end mail");

        } catch (AddressException e) {
            System.out.println("AddressException\t"+e);
        } catch (MessagingException e) {
            System.out.println("MessagingException\t"+e);
        }        
        
    }
    
}
